package com.itheima.d1_threadcreate3;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 掌握创建线程方式3：实现Callable接口
 */
public class ThreadDemo3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //2.创建MyCallable任务对象
        MyCallable mc1 = new MyCallable(100);
        MyCallable mc2 = new MyCallable(10);
        //3.把Callable对象封装成一个真正的线程任务对象FutureTask
        FutureTask ft = new FutureTask<>(mc1);
        FutureTask ft2 = new FutureTask<>(mc2);
        //4.创建线程对象，构造方法中传递FutureTask对象
        Thread t1 = new Thread(ft);
        Thread t2 = new Thread(ft2);
        //启动线程
        t1.start();
        t2.start();
        System.out.println("子线程1"+ft.get());
        System.out.println("子线程2"+ft2.get());


        Thread name = Thread.currentThread();
        System.out.println(name.getName());
    }
}
